package com.hwadee.springboot.controller.ExamController;

import com.hwadee.springboot.entity.Question;
import com.hwadee.springboot.entity.R;
import com.hwadee.springboot.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/examApi/questions")
public class QuestionController {

    @Autowired
    private QuestionService questionService;

    @PostMapping
    public R createQuestion(@RequestBody Question question) {
        boolean saved = questionService.save(question);
        if (saved) {
            return R.ok("题目创建成功", question);
        } else {
            return R.error(500, "题目创建失败");
        }
    }

    @GetMapping
    public R getAllQuestions() {
        List<Question> questions = questionService.list();
        return R.ok("查询成功", questions);
    }
}